package com.wms.consumer.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.amqp.support.converter.MessageConverter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Description: TODO    主题交换机
 *
 * @version 1.0
 * @author: wangqiang
 * @date: 2023/2/19 21:37
 */
@Configuration
public class TopicRabbitConfig {

    /**
     * 绑定值
     */
    public static final String man = "topic.man";
    public static final String woman = "topic.woman";

    @Bean
    public Queue firstQueue () {
        return new Queue(man);
    }

    @Bean
    public Queue secondQueue () {
        return new Queue(woman);
    }

    @Bean
    TopicExchange topicExchange () {
        return new TopicExchange("topicExchange");
    }

    /**
     * Description: TODO 将firstQueue和topicExchange绑定,而且绑定的键值为topic.man , 这样只要是消息携带的路由键是topic.man,才会分发到该队列
     * @author: wangqiang
     * @return: org.springframework.amqp.core.Binding
     * @date: 2023/2/19 22:19
     */
    @Bean
    Binding bindingExchangeMessage () {
        return BindingBuilder.bind(firstQueue()).to(topicExchange()).with(man);
    }

    /**
     * Description: TODO 将secondQueue和topicExchange绑定,而且绑定的键值为用上通配路由键规则topic.# , 这样只要是消息携带的路由键是以topic.开头,都会分发到该队列
     * @author: wangqiang
     * @return: org.springframework.amqp.core.Binding
     * @date: 2023/2/19 22:19
     */
    @Bean
    Binding bindingExchangeMessage2 () {
        return BindingBuilder.bind(secondQueue()).to(topicExchange()).with("topic.#");
    }

}
